fix(publisher): allow cross-origin media in the published CSP - #354
Open
mostafasadeghidev wants to merge 1 commit into
Open
fix(publisher): allow cross-origin media in the published CSP#354mostafasadeghidev wants to merge 1 commit into
mostafasadeghidev wants to merge 1 commit into
Conversation
The base policy set `img-src 'self' data: https:` but never set
`media-src`. An unset `media-src` falls back to `default-src 'self'`, so
every published page loaded a remote image happily and refused every
remote `<video>` / `<audio>`:
Loading media from 'https://…/hover.mp4' violates the following
Content Security Policy directive: "default-src 'self'". Note that
'media-src' was not explicitly set, so 'default-src' is used as a
fallback. The action has been blocked.
Both directives govern passive references that execute nothing, so the
line between them was arbitrary — and invisible from the markup. The
element is right, the URL resolves, the file serves; the video just never
plays and only the console says why.
`media-src` now mirrors `img-src` exactly, and a test asserts they stay
equal rather than pinning the literal string twice.
Found on a site imported from another builder, where per-item hover
videos are served from the source CDN.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The base CSP now sets
media-src 'self' data: https:, mirroringimg-src.Why
createBaseCspPlansetimg-src 'self' data: https:but nomedia-src. An unsetmedia-srcfalls back todefault-src 'self', so every published page would load a remote image happily and refuse every remote<video>/<audio>:Both directives govern passive references that execute nothing, so the line between them was arbitrary. Allowing a remote image while blocking a remote video isn't a security posture, it's an omission.
It is also invisible from the markup, which is what makes it expensive to find. The element is correct, the URL resolves, the file serves with
206 video/mp4— the video simply never plays, and only the browser console says why. I found it by reading the published bytes, confirming the media URL was fine, and then checking the console.How
One directive, same sources as
img-src.The test asserts the two directives are equal to each other rather than pinning the literal string a second time — so if
img-srcis ever tightened or relaxed, the test points at the divergence instead of silently passing.User impact
Relaxes one directive for published pages. No effect on
script-src, which is what actually gates code execution and stays'self'. Sites that host all their media locally are unaffected —'self'was already permitted.Verification
The existing byte-identical-policy test in
cspPlan.test.tswas updated for the new directive (it pins the full serialized string), plus one new test covering the img/media parity.Verified end-to-end: on a real published page, four cross-origin
<video>elements went from CSP-blocked to playing, with no other console errors introduced.